package com.example.demo.zaqizabatest;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @ClassName InternetAddress
 * @Author l42142
 * @Date 2021/3/5 10:16
 * @Description TODO
 * @Version 1.0
 **/
public class InternetAddress {

    public static void main(String[] args) {
        try {
            InetAddress ia1 = InetAddress.getByName("www.qq.com");
            System.out.println(ia1.getHostName());
            System.out.println(ia1.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


        try {
            InetAddress ia2 = InetAddress.getByName("61.135.169.105");
            System.out.println(ia2.getHostName());
            System.out.println(ia2.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


        try {
            InetAddress ia3 = InetAddress.getLocalHost();
            System.out.println("主机名：" + ia3.getHostName());
            System.out.println("本地ip地址：" + ia3.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }


    }
}
